import { _decorator, Component, Node } from 'cc';
import AbstractComponent from '../../base/AbstractComponent';
import { Label } from 'cc';
import { MultiMsgMgr } from './MultiMsgMgr';
import { showErrorTip, showTip } from '../../tools/PopuUp';
import UtilTool from '../../tools/UtilTool';
import { App } from '../../App';
import { PD } from '../../player/PlayerData';
const { ccclass, property } = _decorator;

let NEED_GOLD = 1000

/**
 * 成为球室持有人界面
 */
@ccclass('BeMasterWnd')
export class BeMasterWnd extends AbstractComponent {

    @property(Node)
    content_title : Node = null; // 确认成为持有人节点

    @property(Node)
    content_titl2 : Node = null; // 持有人说明节点

    @property(Label)
    label_need : Label = null; // 需要金币

    cb : Function = null

    start() {
        this.label_need.string = UtilTool.formatStr(App.language.getLanguageLab(2044), NEED_GOLD)
    }

    /**
     * 初始化
     * @param type 
     * @param cb 
     */
    initData(type, cb=null) {
        this.cb = cb
        this.content_title.active = type==1
        this.content_titl2.active = type==2
    }

    onBtnOk() {

        this.playClickAudio()

        // 金币不足
        if(PD.user.coin < NEED_GOLD) {
            showTip(App.language.getLanguageLab(2045))
            return
        }

        // 发送成为球室持有人消息
        MultiMsgMgr.getInstance().sendBeRoomMaster()
        .then((data) => {
            if(data.result == 0) {
                this.cb && this.cb()
                this.close()
            } else {
                showErrorTip(data.result)
            }
        })

    }

}

